import React from 'react';
import { connect } from 'dva';
import resourceActions from '../../../actions/Editor/resources';
import { selectWidgetsByIds, updateWidget } from '../../../actions/Editor/widgets';

import Stereo from './Stereo';
import Plane from './Plane';

const EditorArea = (props) => {
    // 默認不加載3D
    let EditorType = <Plane {...props} />;
    if (props.switchType == 'ThreedAR') {
        EditorType = <Stereo {...props} />;
    }
    return (
      <div>
        {EditorType}
      </div>
    );
};

const mapStateToProps = ({ editor, widgets, timelines, resources }) => {
    const pageId = editor.selectedPageId;
    return {
        editorType: editor.editorType,
        switchType: editor.status.switchType,
        fromTemplate: editor.status.fromTemplate,
        widgets: widgets.filter(w => w.page_id === pageId && !w.delFlag),
        timelines: timelines.filter(t => t.page_id === pageId && !t.delFlag),
        selectedPage: editor.selectedPage,
        selectedWidget: editor.selectedWidget,
        preview: editor.preview,
        scale: editor.scale,
        centerTop: editor.editor,
        centerLeft: editor.centerLeft,
        resources,
    };
};

export default connect(mapStateToProps,{...resourceActions, selectWidgetsByIds, updateWidget})(EditorArea);

